package com.eight.cloud.payment.config;

import cn.hutool.core.bean.BeanUtil;
import com.eight.cloud.core.global.model.AppUser;
import com.eight.cloud.openapi.aspect.OpenApiAspect;
import com.eight.cloud.openapi.interfaces.AuthDetails;
import com.eight.cloud.openapi.interfaces.LogRecordService;
import com.eight.cloud.openfeign.admin.api.AppClient;
import com.eight.cloud.redisson.utils.RedisUtils;
import org.springframework.context.annotation.Bean;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;

/**
 * @ClassName: BeanRegister
 * @Author: TXC
 * @Date: 2024-10-18 12:12
 **/
@Component
public class BeanRegister {
    @Resource
    private AppClient appClient;

    @Resource
    private LogRecordService LogRecordService;

    @Resource
    private RedisUtils redisUtils;

    @Bean
    public OpenApiAspect openApiAspect() {
        return new OpenApiAspect(secretId -> {
            AppUser appVo = appClient.querySecretKey(secretId);
            return new AuthDetails(BeanUtil.toBean(appVo, AppUser.class));
        }, LogRecordService, redisUtils);
    }
}
